package com.tencent.protocol.sendredpack_protocol;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

import com.tencent.common.Configure;
import com.tencent.common.MCHBillnoGenerator;
import com.tencent.common.RandomStringGenerator;
import com.tencent.common.Signature;

public class SendRedpackReqData {

	private String nonce_str = "";
	private String sign = "";
	private String mch_billno = "";
	private String mch_id = "";
	private String wxappid = "";
	private String send_name = "";
	private String re_openid = "";
	private Integer total_amount = 0;
	private Integer total_num = 1;
	private String wishing = "";
	private String client_ip = "";
	private String act_name = "";
	private String remark = "";
	
	public SendRedpackReqData(String send_name,String re_openid,Integer total_amount,Integer total_num,String wishing,String client_ip,String act_name,String remark){
		
		//随机数
		setNonce_str(RandomStringGenerator.getRandomStringByLength(32));
		
		//商户订单号（每个订单号必须唯一）组成：mch_id+yyyymmdd+10位一天内不能重复的数字。接口根据商户订单号支持重入，如出现超时可再调用。
		setMch_billno(MCHBillnoGenerator.getMCHBillno(Configure.getMchid()));
		
		//微信支付分配的商户号
		setMch_id(Configure.getMchid());
		
		//微信分配的公众账号ID（企业号corpid即为此appId）。接口传入的所有appid应该为公众号的appid（在mp.weixin.qq.com申请的），不能为APP的appid（在open.weixin.qq.com申请的）。 
		setWxappid(Configure.getAppid());
		
		//红包发送者名称
		setSend_name(send_name);
		
		//接受红包的用户用户在wxappid下的openid
		setRe_openid(re_openid);
		
		//付款金额，单位分
		setTotal_amount(total_amount);
		
		//红包发放总人数total_num=1
		setTotal_num(total_num);
		
		//红包祝福语.例：感谢您参加猜灯谜活动，祝您元宵节快乐！
		setWishing(wishing);
		
		//调用接口的机器Ip地址
		setClient_ip(client_ip);
		
		//活动名称
		setAct_name(act_name);
		
		//备注信息
		setRemark(remark);
		
		//根据API给的签名规则进行签名
        String sign = Signature.getSign(toMap());
        setSign(sign);//把签名数据设置到Sign这个属性中
	}
	
    public String getNonce_str() {
		return nonce_str;
	}

	public void setNonce_str(String nonce_str) {
		this.nonce_str = nonce_str;
	}

	public String getSign() {
		return sign;
	}

	public void setSign(String sign) {
		this.sign = sign;
	}

	public String getMch_billno() {
		return mch_billno;
	}

	public void setMch_billno(String mch_billno) {
		this.mch_billno = mch_billno;
	}

	public String getMch_id() {
		return mch_id;
	}

	public void setMch_id(String mch_id) {
		this.mch_id = mch_id;
	}

	public String getWxappid() {
		return wxappid;
	}

	public void setWxappid(String wxappid) {
		this.wxappid = wxappid;
	}

	public String getSend_name() {
		return send_name;
	}

	public void setSend_name(String send_name) {
		this.send_name = send_name;
	}

	public String getRe_openid() {
		return re_openid;
	}

	public void setRe_openid(String re_openid) {
		this.re_openid = re_openid;
	}

	public Integer getTotal_amount() {
		return total_amount;
	}

	public void setTotal_amount(Integer total_amount) {
		this.total_amount = total_amount;
	}

	public Integer getTotal_num() {
		return total_num;
	}

	public void setTotal_num(Integer total_num) {
		this.total_num = total_num;
	}

	public String getWishing() {
		return wishing;
	}

	public void setWishing(String wishing) {
		this.wishing = wishing;
	}

	public String getClient_ip() {
		return client_ip;
	}

	public void setClient_ip(String client_ip) {
		this.client_ip = client_ip;
	}

	public String getAct_name() {
		return act_name;
	}

	public void setAct_name(String act_name) {
		this.act_name = act_name;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public Map<String,Object> toMap(){
        Map<String,Object> map = new HashMap<String, Object>();
        Field[] fields = this.getClass().getDeclaredFields();
        for (Field field : fields) {
            Object obj;
            try {
                obj = field.get(this);
                if(obj!=null){
                    map.put(field.getName(), obj);
                }
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
        return map;
    }
}
